package com.shujia

object Code02BaseScala {
  def main(args: Array[String]): Unit = {

    var age = 20
    if(age >= 20){
      println("this is if age >= 20")
    }

    if (age > 20) {
      println("this is if age > 20")
    }else {
      println("this is else age <= 20")
    }

    age = 10
    // 多条件判断
    if (age <=  0 || age >= 150) {
      println("age is error")
    } else if (age <=18){
      println("未成年..")
    }else{
      println("已成年...")
    }

    // Scala中的控制语句可以存在有返回值

    age = 10
    // 多条件判断
    val ifRes:Int = if (age <= 0 || age >= 150) {
      println("age is error")
      0
    } else if (age <= 18) {
      println("未成年..")
      1
    } else {
      println("已成年...")
      2
    }
    println(ifRes)

    age = 10
    // 多条件判断
    val ifRes2: Any = if (age <= 0 || age >= 150) {
      println("age is error")
      0
    } else if (age <= 18) {
      println("未成年..")
      1
    } else {
      println("已成年...")
      "2"
    }
    println(ifRes2)


    // while循环
    var whileNum = 0
    while (whileNum <= 10){
      println("while执行了依次..")
      whileNum += 1
    }

    // Scala中也可以使用 do while语句
    whileNum = 0
    do {
      println("while执行了依次..")
      whileNum += 1
    }while(whileNum <= 10)





  }
}
